package Four;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:lenovo
 * Date:2024-06-01
 * Time:16:03
 */


import java.util.ArrayList;
import java.util.Scanner;

class Notepad {
    private ArrayList<String> records;

    public Notepad() {
        records = new ArrayList<>();
    }

    public int getRecordCount() {
        return records.size();
    }

    public void addRecord(String record) {
        records.add(record);
    }

    public void showAllRecords() {
        if (records.isEmpty()) {
            System.out.println("No records found.");
        } else {
            System.out.println("All records:");
            for (int i = 0; i < records.size(); i++) {
                System.out.println((i + 1) + ") " + records.get(i));
            }
        }
    }

    public void showRecord(int index) {
        if (index >= 1 && index <= records.size()) {
            System.out.println("Record " + index + ": " + records.get(index - 1));
        } else {
            System.out.println("Invalid record index.");
        }
    }

    public void deleteAllRecords() {
        records.clear();
        System.out.println("All records deleted.");
    }

    public void deleteRecord(int index) {
        if (index >= 1 && index <= records.size()) {
            records.remove(index - 1);
            System.out.println("Record " + index + " deleted.");
        } else {
            System.out.println("Invalid record index.");
        }
    }
}

public class Test3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Notepad notepad = new Notepad();

        System.out.println("Welcome to the Notepad application!");

        while (true) {
            System.out.println("\nPlease select an operation:");
            System.out.println("1. Add a record");
            System.out.println("2. Show all records");
            System.out.println("3. Show a specific record");
            System.out.println("4. Delete all records");
            System.out.println("5. Delete a specific record");
            System.out.println("0. Exit");

            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline character

            switch (choice) {
                case 1:
                    System.out.println("Enter the record:");
                    String record = scanner.nextLine();
                    notepad.addRecord(record);
                    System.out.println("Record added successfully.");
                    break;
                case 2:
                    notepad.showAllRecords();
                    break;
                case 3:
                    System.out.println("Enter the record index:");
                    int index = scanner.nextInt();
                    scanner.nextLine(); // Consume newline character
                    notepad.showRecord(index);
                    break;
                case 4:
                    notepad.deleteAllRecords();
                    break;
                case 5:
                    System.out.println("Enter the record index:");
                    int delIndex = scanner.nextInt();
                    scanner.nextLine(); // Consume newline character
                    notepad.deleteRecord(delIndex);
                    break;
                case 0:
                    System.out.println("Exiting the Notepad application. Goodbye!");
                    System.exit(0);
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }
}

